package control;

import model.Leader;
import dbconn.DBConnect;

/*****
 * 队长信息管理类
 * 队长信息添加
 * 队长信息修改
 * 队长信息删除
 * @author CYoung
 *date 05/12/2012
 */
public class LeaderControl {
	public static boolean addLeader(Leader l) {
		DBConnect dbConnect=  new DBConnect();
		String sql = "insert into leader(description,pic) values(?,?)";
		dbConnect.prepareStatement(sql);
		try {
			dbConnect.setString(1, l.getDescription());
			dbConnect.setString(2, l.getPic());
			dbConnect.executeUpdate();
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}finally{
			dbConnect.close();
		}
	}
	
	public static boolean updateLeader(Leader l,int id) {
		DBConnect dbConnect = new DBConnect();
		String sql = "update leader set description=?,pic=? where id=?";
	    dbConnect.prepareStatement(sql);
		try {
			dbConnect.setString(1, l.getDescription());
			dbConnect.setString(2, l.getPic());
			dbConnect.setInt(3, id);
			dbConnect.executeUpdate();
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}finally{
			dbConnect.close();
		}
	}
	
	public static boolean deleteLeader(int id){
		DBConnect dbConnect= new DBConnect();
		String sql ="delete from leader where id ='"+id+"'";
		dbConnect.prepareStatement(sql);
		try {
			dbConnect.executeUpdate();
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}finally{
			dbConnect.close();
		}
	}

}
